<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="css/common.css" type="text/css" />
<title><?php echo $titlestr;?></title>
<script language="javascript" src="js/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="swfupload/swfupload.js"></script>
<script type="text/javascript" src="swfupload/goodsupload/swfupload.queue.js"></script>
<script type="text/javascript" src="swfupload/goodsupload/fileprogress.js"></script>
<script type="text/javascript" src="swfupload/goodsupload/handlers.js"></script>
<script src="./js/calendar/js/jscal2.js"  language="javascript" charset="utf-8"></script>
<script src="./js/calendar/js/lang/cn.js" language="javascript" charset="utf-8"></script>
<link rel="stylesheet" type="text/css" href="./js/calendar/css/jscal2.css" />
<link rel="stylesheet" type="text/css" href="./js/calendar/css/border-radius.css" />
<link rel="stylesheet" type="text/css" href="./js/calendar/css/border-radius.css" />
<link rel="stylesheet" type="text/css" href="./js/calendar/css/steel/win2k/win2k.css" />
<script type="text/javascript" charset="utf-8" src="./kindeditor/kindeditor.js"></script>
<script type="text/javascript">
    KE.show({
        id : 'goods_reviews_site',
        cssPath : './kindeditor/index.css',
		urlType : 'absolute'
    });
    KE.show({
        id : 'goods_about',
        cssPath : './kindeditor/index.css',
		urlType : 'absolute'
    });
    KE.show({
        id : 'goods_brief',
        cssPath : './kindeditor/index.css',
		urlType : 'absolute'
    });
    KE.show({
        id : 'goods_reviews',
        cssPath : './kindeditor/index.css',
		urlType : 'absolute'
    });
	
	</script>
<script language="javascript">
$(document).ready(function(){

//點擊事件切換 全選取消狀態
$("#selectall").click( function (){ $("#grouplist").toggleCheckboxes(); });
refresh_img_list_box();
});

function setgallery(aid){
	$.get("groups_add.php?action=ajaxgetbigimg&aid="+aid, function(data){
  		$("#goods_img_box").attr("src",data);
		$("#gallery_id").val(aid);
		refresh_img_list_box();
});}

function delgallery(aid){
$.get("groups_add.php?action=ajaxdelimg&aid="+aid, function(data){
		dom="#div_"+aid;
		$(dom).remove();
		
});}

function addReviewsList()
{
	$("#reviewsLis").append($("#goodsReviewsListHtml").html());
}

function delReviewsList(obj,id)
{
	if(id > 0)
	{
		
		$(obj).parent().parent().remove();
			
	}
	else
		$(obj).parent().parent().remove();
}
function refresh_img_list_box()
{
	var curr_id = $("#gallery_id").val();
	var thumb_list = document.getElementById("gallery_list").getElementsByTagName("IMG");
	var input_list = document.getElementById("gallery_list").getElementsByTagName("INPUT");
	for(var i=0;i<input_list.length;i++)
	{
		if(input_list[i].value == curr_id)
		{
			thumb_list[i].className="selectborder";
		}
		else
		{
			thumb_list[i].className = "";
		}
	}
}

$(document).ready(function(){
$("#groupaddform").submit(function(){

		var title = $.trim($("#title").val());
		var sn = $.trim($("#sn").val());
		var sid = $.trim($("#sid").val());
		var market_price = $.trim($("#market_price").val());
		var shop_price = $.trim($("#shop_price").val());
		var max_buynum = $.trim($("#max_buynum").val());
		var stock = $.trim($("#stock").val());
		var group_begin_time = $.trim($("#group_begin_time").val());
		var group_end_time = $.trim($("#group_end_time").val());
		var error="";
		if(title.length == 0)
		{
			error=error+"【團購標題】不能為空!\r\n\n";
		}
		if(sid.length == 0)
		{
			error=error+"【供貨商家】不能為空!\r\n\n";
		}
		if(sn.length == 0)
		{
			error=error+"【商品貨號】不能為空!\n\n";
		}
		if(market_price.length == 0)
		{
			error=error+"【市場價格】不能為空!\n\n";
		}
		if(shop_price.length == 0)
		{
			error=error+"【團購價格】不能為空!\n\n";
		}
		if(max_buynum.length == 0)
		{
			error=error+"【用戶最大購買數】不能為空!\n\n";
		}
		if(stock.length == 0)
		{
			error=error+"【庫存總數量】不能為空!\n\n";
		}
		if(group_begin_time.length == 0)
		{
			error=error+"【團購開始時間】不能為空!\n\n";
		}
		if(group_end_time.length == 0)
		{
			error=error+"【團購結束時間】不能為空!\n\n";
		}

		if(error==""){
		return true;
		}else{
		alert(error);
		return false;
		}		
});
});


</script>

<style>
.gallery_list {width:100%;}
.gallery_list div{ float:left; width:64px; text-align:center; margin-right:4px; margin-bottom:4px; padding:4px; border:#ccc solid 1px;}
.gallery_list div img{ width:60px; height:42px;border:#ccc solid 2px; cursor:pointer;}
.gallery_list div img.selectborder{ width:60px; height:42px; border:#ffa200 solid 2px; cursor:pointer;}
#goods_img_box{ border:#ccc solid 2px;}
#uploaderimg{ color:#ccc; font-size:12px; }

</style>
</head>

<body>
<div id="man_zone">
<form action="?action=save" method="post" enctype="application/x-www-form-urlencoded" name="groupaddform" id="groupaddform">

<table width="99%"  align="center" cellpadding="0" cellspacing="0"   class="table_style">
  <tr>
    <td width="47%" align="center"><table width="90%" height="600" border="0" cellpadding="0" cellspacing="1">
      <tr>
        <td width="28%" align="right">團購標題：</td>
        <td width="72%" align="left"><input name="title" type="text" id="title" value="<?php if($show)echo $xmldata['gtitle']?>" /></td>
      </tr>
      <tr>
        <td align="right">商品種類：</td>
        <td align="left"><input name="subtitle" type="text" id="subtitle"  value="<?php if($show)echo $xmldata['gsubtilte']?>"/>(請用分號分開,如: 巧克力;藍莓;草莓)</td>
      </tr>
      <tr>
        <td align="right">分店位置：</td>
        <td align="left"><input name="local" type="text" id="local"  value="<?php if($show)echo $xmldata['glocal']?>"/>(請用分號分開,如: 台北;桃園;台中)</td>
      </tr>
      <tr>
        <td align="right">商品貨號：</td>
        <td align="left"><input name="sn" type="text" id="sn"  value="<?php if($show)echo $xmldata['gid']?>"/></td>
      </tr>
      <tr>
        <td align="right">地區分類：</td>
        <td align="left"><?php if(empty($cityselect))echo"<a href='city_manage.php?action=add'> [點擊添加地區]</a>"; else echo $cityselect?>
        </td>
      </tr>
      <tr>
        <td align="right">供貨商家：</td>
        <td align="left">
		<?php if(empty($sidselect))echo"<a href='suppliers_add.php'> [點擊添加供貨商]</a>"; else echo $sidselect?>		</td>
      </tr>
      <tr>
        <td align="right">商品類型：</td>
        <td align="left"><select name="gtypeid" class="bLeft" id="gtypeid">
                <option value="0" <?php if($show&&$xmldata['gtypeid']==0)echo "selected='selected'"?>>團購券，序列號+密碼</option>
                <option value="1" <?php if($show&&$xmldata['gtypeid']==1)echo "selected='selected'"?>>實體商品，需要配送</option>
              <!--  <option value="2">線下訂購商品</option>  !-->
			  </select></td>
      </tr>
      <tr>
        <td align="right">是否免運費：</td>
        <td align="left"><select name="freefreight" id="freefreight">
          <option value="1" <?php if($show&&$xmldata['freefreight']==1)echo "selected='selected'"?>>免運費</option>
          <option value="0" <?php if($show&&$xmldata['freefreight']==0)echo "selected='selected'"?>>不免運費</option>
                </select></td>
      </tr>
      <tr>
        <td align="right">排序：</td>
        <td align="left"><input name="order" type="text" id="order" size="20" onkeyup="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')" value="0"/></td>
      </tr>
      <tr>
        <td align="right">尺寸：</td>
        <td align="left"><input name="weight" type="text" id="weight" size="20" onkeyup="if(isNaN(value))execCommand('undo')" onafterpaste="if(isNaN(value))execCommand('undo')"  value="<?php if($show)echo $xmldata['gid']?>"/></td>
      </tr>
      <tr>
        <td align="right">可獲積分：</td>
        <td align="left"><input name="score" type="text" id="score" size="20" onkeyup="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')" value="0"/></td>
      </tr>
      <tr>
        <td align="right">市場價格：</td>
        <td align="left"><input name="market_price" type="text" id="market_price" size="20" onkeyup="if(isNaN(value))execCommand('undo')" onafterpaste="if(isNaN(value))execCommand('undo')" value="<?php if($show)echo $xmldata['market_price']?>"/>
	

		</td>
      </tr>
      <tr>
        <td align="right">團購價格：</td>
        <td align="left"><input name="shop_price" type="text" id="shop_price" size="20"   value="<?php if($show)echo $xmldata['shop_price']?>"/></td>
      </tr>
      <tr>
        <td align="right">預付款：</td>
        <td align="left"><input name="earnest_money" type="text" id="earnest_money" size="20" onkeyup="if(isNaN(value))execCommand('undo')" onafterpaste="if(isNaN(value))execCommand('undo')" value="0"/></td>
      </tr>
      <tr>
        <td align="right">庫存總數量：</td>
        <td align="left"><input name="stock" type="text" id="stock" size="20" onkeyup="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')"  value="<?php if($show)echo $xmldata['stock']?>"/></td>
      </tr>
      <tr>
        <td align="right">用戶最大購買數：</td>
        <td align="left"><input name="max_buynum" type="text" id="max_buynum" size="20" onkeyup="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')"  value="10"/></td>
      </tr>
      <tr>
        <td align="right">最低團購人數：</td>
        <td align="left"><input name="group_usernum" type="text" id="group_usernum" size="20" onkeyup="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')"  value="<?php if($show)echo $xmldata['group_usernum']?>"/></td>
      </tr>
      <tr>
        <td align="right">團購人數起始值：</td>
        <td align="left"><input name="group_startnum" type="text" id="group_startnum" size="20" onkeyup="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')"  value="0"/></td>
      </tr>	  
	  
      <tr>
        <td align="right">團購券過期時間：</td>
        <td align="left"><input name="group_bond_end_time" type="text" id="group_bond_end_time" size="20"  value="<?php echo date( "Y-m-d H:i",strtotime( "+30 days "))?>"/>
          &nbsp;
          <input type="button" id="group_bond_end_timebtn"  onclick="javascript:;" value="..." /></td>
      </tr>
      <tr>
        <td align="right">團購開始時間：</td>
        <td align="left" style=""><input name="group_begin_time" type="text" id="group_begin_time" size="20"  value="<?php echo date( "Y-m-d H:i")?>"/> &nbsp;
          <input type="button"  id="group_begin_timebtn"  onclick="javascript:;" value="..." /></td>
      </tr>
      <tr>
        <td align="right">團購結束時間：</td>
        <td align="left"><input name="group_end_time" type="text" id="group_end_time" size="20"  value="<?php echo date( "Y-m-d H:i",strtotime( "+1 days "))?>"/> &nbsp;
          <input type="button"  id="group_end_timebtn"  onclick="javascript:;" value="..." /></td>
      </tr>

    </table></td>
    <td width="53%" valign="top">
	<div id=loader style="display:none;">上傳中。。。。。。。</div> 
	<TABLE border="0" cellpadding=1 cellspacing=1 >
		<tr>
			<td>
			<table border="0" cellpadding="0" cellspacing="0">
				<tr>
					<td width="120">
						<div id="divStatus" style="display:none;"></div>
						<input id="btnCancel" type="hidden" />
						<span id="image_browse"></span>
					</td>
					<td>
						<div class="fieldset flash" id="fsUploadProgress" style="display:none;" ></div>
						<div id="uploaderimg">可同時批量上傳多張圖片</div>
					</td>
				</tr>
			</table>
			</td>
		</tr>
		<tr>
			<td>
			<img src="../<?php if($show)echo $arrayimg[$xmldata['goods_pic']]['filepath']?>" onerror="this.src='images/noimg.gif'" width="440" height="267" id="goods_img_box" />
			<input type="hidden" name="gallery_id" id="gallery_id"  value="<?php if($show)echo $xmldata['goods_pic']?>" />
			</td>
		</tr>
		<tr>
			<td>
				<!-- 圖片列表 -->
				<div id="gallery_list" class="gallery_list" >
				<?php 
				if($show && is_array($arrayimg)){
				foreach($arrayimg as $img){
				?>
<DIV id=div_<?php echo $img['aid']?>>
<INPUT value=<?php echo $img['aid']?> type=hidden name=goods_gallerys[]><IMG onclick=setgallery(<?php echo $img['aid']?>) src="../<?php echo $img['thumb']?>"><BR><A onclick=delgallery(<?php echo $img['aid']?>,this) href="javascript:;">刪除</A>
</DIV>
				
				<?php }}?>				
				</div>
				<!-- 圖片列表 -->

				
				
			</td>
		</tr>
		</TABLE>
		<script type="text/javascript">
		var gid=0;//團購ID 新增時候團購ID為0
		var adminauth="<?php echo get_cookie('adminauth');?>";
		var settings = {
				flash_url : "swfupload/swfupload.swf",
				upload_url: "groups_add.php?action=ajaxuploadimg",				
				post_params: {"gid":gid,"adminauth":adminauth},
				file_size_limit : "1MB",
				file_types : "*.jpg;*.gif",
				file_types_description : "不可超過1MB",
				file_upload_limit : 100,
				file_queue_limit : 100,
				custom_settings : {
					progressTarget : "fsUploadProgress",
					cancelButtonId : "btnCancel"
				},
				debug: false,
 
				// Button settings
				button_image_url: "swfupload/uploadbtn.png",
				button_width: "100",
				button_height: "30",
				button_placeholder_id: "image_browse",
 
				
				// The event handler functions are defined in handlers.js
				file_queued_handler : fileQueued,
				file_queue_error_handler : fileQueueError,
				file_dialog_complete_handler : fileDialogComplete,
				upload_start_handler : uploadStart,
				upload_progress_handler : uploadProgress,
				upload_error_handler : uploadError,
				upload_success_handler : uploadSuccess,
				upload_complete_handler : uploadComplete,
				queue_complete_handler : queueComplete	// Queue plugin event
			};
			var swfu = new SWFUpload(settings);
		</script>
		<!-- 圖片上傳塊 -->

	
	</td>
  </tr>
</table>

<table width="94%" border="0" align="center" cellpadding="1" cellspacing="1">
  <tr>
    <td height="30" colspan="2" align="center" bgcolor="#EAEAEA"><strong>商品信息</strong></td>
  </tr>
  <tr>
    <td width="12%" align="right">本站點評：</td>
    <td width="88%"><textarea name="goods_reviews_site" cols="100" rows="12" id="goods_reviews_site"><?php if($show)echo $xmldata['goods_reviews_site']?></textarea>
      <br /></td>
  </tr>
  <tr>
    <td align="right">商品描述：</td>
    <td><textarea name="goods_about" cols="100" rows="12" id="goods_about"><?php if($show)echo $xmldata['goods_about']?></textarea></td>
  </tr>
  <tr>
    <td align="right">商品簡介：</td>
    <td><textarea name="goods_brief" cols="100" rows="12" id="goods_brief"><?php if($show)echo $xmldata['goods_brief']?></textarea></td>
  </tr>
  <tr>
    <td align="right">SEO關鍵詞：</td>
    <td><textarea name="seokeyword" cols="100" rows="3" id="seokeyword"><?php if($show)echo $xmldata['seokeyword']?></textarea></td>
  </tr>
  <tr>
    <td align="right">SEO描述：</td>
    <td><textarea name="seocontent" cols="100" rows="3" id="seocontent"><?php if($show)echo $xmldata['seocontent']?></textarea></td>
  </tr>
  <tr>
    <td height="30" colspan="2" align="center" bgcolor="#EAEAEA"><strong>商品點評</strong></td>
  </tr>
  <tr>
    <td align="right">商品點評：</td>
    <td><textarea name="goods_reviews" cols="100" rows="12" id="goods_reviews"><?php if($show)echo $xmldata['goods_reviews']?></textarea></td>
  </tr>
  <tr>
    <td align="right">用戶點評列表：</td>
    <td><a href="###" onclick="addReviewsList()">【點擊添加】
        
    </a></td>
  </tr>
  <tr>
    <td colspan="2" id="reviewsLis">
     
     <?php

	$datalist=unserialize($xmldata['goods_reviews_contents']);
	if($show && is_array($datalist)){
	 foreach($datalist as $data){
	 ?>
	 
	<div style="border-top:solid 2px #333; padding:8px 0;">
        <textarea name="goods_reviews_content[]" class="bLeft" style="width:80%; height:50px;"><?php echo $data['content']?></textarea>
        <div style="margin:5px 0 0 0;">
            <span>用戶名稱：</span><input type="text" name="goods_reviews_user[]" class="bLeft" style="width:100px;"  value="<?php echo $data['user']?>"/>&nbsp;&nbsp;
            <span>點評網址：</span><input type="text" name="goods_reviews_url[]" class="bLeft" style="width:150px;"   value="<?php echo $data['url']?>"/>&nbsp;&nbsp;
            <span>點評網站：</span><input type="text" name="goods_reviews_web[]" class="bLeft" style="width:150px;"   value="<?php echo $data['web']?>"/>&nbsp;&nbsp;[<a href="javascript:;" onclick="delReviewsList(this,0)">刪除</a>]
        </div>
    </div>

	 
	 <?php }} ?>
	 
	 </td>
  </tr>
  <tr>
    <td colspan="2" align="center"><label>
      <input type="submit" name="Submit" value="提交" />
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      <input type="reset" name="Submit2" value="重置" />
    </label></td>
  </tr>
</table>
</form>
</div>

<div id="goodsReviewsListHtml" style="display:none;">
	<div style="border-top:solid 2px #333; padding:8px 0;">
        <textarea name="goods_reviews_content[]" class="bLeft" style="width:80%; height:50px;"></textarea>
        <div style="margin:5px 0 0 0;">
            <span>用戶名稱：</span><input type="text" name="goods_reviews_user[]" class="bLeft" style="width:100px;" />&nbsp;&nbsp;
            <span>點評網址：</span><input type="text" name="goods_reviews_url[]" class="bLeft" style="width:150px;" />&nbsp;&nbsp;
            <span>點評網站：</span><input type="text" name="goods_reviews_web[]" class="bLeft" style="width:150px;" />&nbsp;&nbsp;[<a href="javascript:;" onclick="delReviewsList(this,0)">刪除</a>]
        </div>
    </div>
</div>

</body>
</html>
  	<script type="text/javascript">
	//<![CDATA[

      var cal = Calendar.setup({
          onSelect: function(cal) { cal.hide() },
          showTime: true
      });
      cal.manageFields("group_bond_end_timebtn", "group_bond_end_time", "%Y-%m-%d %H:%M");
	  cal.manageFields("group_begin_timebtn", "group_begin_time", "%Y-%m-%d %H:%M");
	  cal.manageFields("group_end_timebtn", "group_end_time", "%Y-%m-%d %H:%M");
		
    //]]>
	</script>
